package com.gxa.service.points.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.common.utils.ImageUtil;
import com.gxa.entity.points.ExchangeRecord;
import com.gxa.entity.points.Gift;
import com.gxa.mapper.points.GiftMapper;
import com.gxa.service.points.GiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:43:53
 */
@Service
public class GiftServiceImpl extends ServiceImpl<GiftMapper, Gift> implements GiftService {

    @Autowired
    private GiftMapper giftMapper;
    @Override
    public List<Gift> queryAll() {
        List<Gift> giftList = this.giftMapper.queryAll();
        return giftList;
    }

    @Override
    public void add(Gift gift,MultipartFile multipartFile){
        System.out.println("来上传文件了");
        System.out.println(multipartFile.getName());
        if (multipartFile.isEmpty() || multipartFile == null) {
            System.out.println("上传失败");
        } else {
            String address = ImageUtil.upload(multipartFile);
            gift.setGiftPic(address);
            this.giftMapper.insert(gift);
        }
    }

    @Override
    public void delete(Integer id) {
        this.giftMapper.deleteById(id);
    }

    @Override
    public void update(Gift gift,MultipartFile multipartFile) {

        System.out.println("来上传文件了");
        System.out.println(multipartFile.getName());
        if (multipartFile.isEmpty() || multipartFile == null) {
            System.out.println("上传失败");
        } else {
            String address = ImageUtil.upload(multipartFile);
            gift.setGiftPic(address);
            this.giftMapper.updateById(gift);
        }
    }

    @Override
    public Gift queryId(Integer id) {
        Gift gift = this.giftMapper.queryById(id);
        return gift;
    }

    @Override
    public void updateByid(Integer id,Integer status) {
        this.giftMapper.updateId(id,status);
    }

    @Override
    public List<Gift> queryByName(String name) {
        List<Gift> gifts = this.giftMapper.queryByGiftName(name);
        return gifts;
    }

    @Override
    public List<Gift> queryList() {
        List<Gift> gifts = this.giftMapper.queryList();
        return gifts;
    }

}
